package com.mxl.threadtest;

public class MyDaemonThreadTest {
    public static void main(String[] args) throws Exception {

        MyDaemonThread daemonThread = new MyDaemonThread();
        //设置为守护线程为用户线程服务, 垃圾回收机制就是典型的守护进程
        daemonThread.setDaemon(true);
        daemonThread.start();

        for (int i = 1; i <= 10; i++) {
            Thread.sleep(2 * 1000);
            System.out.println("A在辛苦的工作...+" + i);
        }
    }
}

class MyDaemonThread extends Thread {
    @Override
    public void run() {
        for (; ; ) {
            try {
                //休眠 1s
                Thread.sleep(2 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("A和B还在聊天.....");
        }
    }
}
